/**
 * 动态reader 与动态表格结合
 * 
 * @author 攻心小虫
 */
Ext.apply(Ext.data.Types, {
    FLOATORSTRING: {
        convert: function(v, n) {
            v = Ext.isNumeric(v) ? Number(v) : v;
            return v;
        },
        sortType: function(v) {
            v = Ext.isNumeric(v) ? Number(v) : v;
            return v;
        },
        type: 'floatOrString'
    }
});

Ext.define('cceaf.control.DynamicReader', {
    extend: 'Ext.data.reader.Json',
    alias: 'reader.dynamicReader',
    visibleColumns: undefined,
    readRecords: function(json) {
    	var data = json.data;
        if (data.length > 0) {
            var item = data[0];
            var fields = [];
            var columns = [{xtype: 'rownumberer',header:'序号'}];
            for (p in item) {
                fields.push({name: p, type: 'floatOrString'});
                var conf ={};
                conf.dataIndex = p;
                conf.header = p;
                columns.push(conf);
            }

            data.metaData = { fields: fields, columns: columns };
        }
        if(json.message && json.message != null && json.message != ''){
        	cceaf.util.ExtHelper.showErrorDialog(json.message);
        }
        return this.callParent([data]);
    }
});